#pragma once
#include "FCMiddleware_global.h"
#include <QObject>
#include <QtSerialPort/QSerialPort>

namespace FCMiddleware
{
    class FCMIDDLEWARE_EXPORT SerialClient : public QObject
	{
		Q_OBJECT

	public:
		SerialClient(QObject *parent = nullptr);
		SerialClient(const QString& portName, unsigned int baud = 115200, QObject *parent = nullptr);
		~SerialClient();

	protected:
		QString _portName;
		unsigned int _baud;
		QSerialPort::Parity _parity;

		QSerialPort* _serialPort;

	public:
		void setPortParams(const QString& portName, unsigned int baud = 115200, QSerialPort::Parity parity = QSerialPort::NoParity);
		int open();
		void close();
		virtual int recv(unsigned char* buff, unsigned short size, int* err);
		virtual int send(char* buff, unsigned short size, int* err);
	};
}

